export default {
	state: {
		address: JSON.parse(uni.getStorageSync('address') || '{}'),
		token: uni.getStorageSync('token') || '',
		// 用户的信息对象
		userInfo: JSON.parse(uni.getStorageSync('userinfo') || '{}'),
		// 重定向的Object 对象
		redirectInfo: null
	},
	getters: {
		addstr(state) {
			if (!state.address.provinceName) { return '' } else {
				return state.address.provinceName + state.address.cityName + state.address.countyName + state.address
					.detailInfo
			}
		},
	},
	mutations: {
		// 跟新收获地址
		updateAddress(state, address) {
			state.address = address
			this.commit('saveAddressToStoreage')
		},
		// 持久化存储
		saveAddressToStoreage(state) {
			uni.setStorageSync('address', JSON.stringify(state.address))
		},
		// 更新用户的基本信息
		updateUserInfo(state, userinfo) {
			state.userInfo = userinfo
			this.commit('saveUserInfoToStorage')
		},
		// 持久化存储用户信息
		saveUserInfoToStorage(state) {
			uni.setStorageSync('userinfo', JSON.stringify(state.userInfo))
		},
		// 更新token
		updateToken(state, token) {
			console.log('token' + token);
			state.token = token
			this.commit('saveTokenToStorage')
		},
		saveTokenToStorage(state) {
			uni.setStorageSync('token', state.token)
		},
		updateRedirectInfo(state, info) {
			state.redirectInfo = info
		}
	},
	actions: {}
}
